//
//  WKHomePageVC.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/21.
//  Copyright © 2018 何文虎. All rights reserved.
//

#import "WKHomePageVC.h"
#import "WKTalkHomePageVC.h"
#import "WKCareListVC.h"
#import "WKVideoListVC.h"
#import "WKStrategyListVC.h"
#import "WKSearchListVC.h"

@interface WKHomePageVC ()<UIScrollViewDelegate,JXCategoryViewDelegate>
{
    UIButton *_searchBtn;
}
@property(nonatomic,strong)NSArray *titles;
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)JXCategoryTitleView *categoryView;
@property (nonatomic, assign) NSInteger currentIndex;
@end

@implementation WKHomePageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViews];
}

- (void)initViews{
    [self hideMyNaviBar];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.titles = @[@"推荐", @"关注", @"视频",@"攻略"];
    
    CGFloat  categoryViewHeight = NavBarHeight - StatusBarHeight -1;
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight-NavBarHeight)];
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(ScreenWidth*4, 0);
    self.scrollView.bounces = NO;
    [self.view addSubview:self.scrollView];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    WKTalkHomePageVC *vc1 = [[WKTalkHomePageVC alloc] init];
    [self addChildViewController:vc1];
     vc1.view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight-NavBarHeight);
    [self.scrollView addSubview:vc1.view];
    
    WKCareListVC *vc2 = [[WKCareListVC alloc] init];
    [self addChildViewController:vc2];
    vc2.view.frame = CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeight-NavBarHeight);
    [self.scrollView addSubview:vc2.view];
    
    WKVideoListVC *vc3 = [[WKVideoListVC alloc] init];
    [self addChildViewController:vc3];
    vc3.view.frame = CGRectMake(ScreenWidth*2, 0, ScreenWidth, ScreenHeight-NavBarHeight);
    [self.scrollView addSubview:vc3.view];
    
    WKStrategyListVC *vc4 = [[WKStrategyListVC alloc] init];
     vc4.view.frame = CGRectMake(ScreenWidth*3, 0, ScreenWidth, ScreenHeight-NavBarHeight);
    [self addChildViewController:vc4];
    [self.scrollView addSubview:vc4.view];


    
    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake((ScreenWidth-250)/2, StatusBarHeight, 250, categoryViewHeight)];
    self.categoryView.titles = _titles;
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
    self.categoryView.titleSelectedColor = UIColorFromHex(0x3C3C3C);
    self.categoryView.titleColor = UIColorFromHex(0x979797);
    self.categoryView.titleFont = PFSC_MediumFont(15);
    self.categoryView.titleSelectedFont = PFSC_MediumFont(13);
    self.categoryView.titleColorGradientEnabled = NO;
    self.categoryView.titleLabelZoomEnabled = YES;
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, NavBarHeight-1, ScreenWidth, 1)];
    line.backgroundColor = LINEBACK_COLOR;
    line.layer.shadowColor = [UIColor blackColor].CGColor;
    line.layer.shadowOpacity = 0.1f;
    line.layer.shadowOffset = CGSizeMake(0,1);
    [self.view addSubview:line];
    
    _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _searchBtn.frame = CGRectMake(12, StatusBarHeight+4, 40, 36);
    _searchBtn.backgroundColor = [UIColor greenColor];
    [_searchBtn addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_searchBtn];
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorLineViewColor = BACK_COLOR;
    lineView.lineStyle = JXCategoryIndicatorLineStyle_JD;
//    lineView.indicatorLineWidth = 35;
    self.categoryView.indicators = @[lineView];
    self.categoryView.contentScrollView = self.scrollView;
    
    
    [self.view addSubview:self.categoryView];

   
}

#pragma mark - 搜索
- (void)searchAction:(UIButton*)sender{
    WKSearchListVC *searchVC = [[WKSearchListVC alloc]init];
    searchVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:searchVC animated:NO];
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
